Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: support server-side batch check endpoiont #185

Merged
merged 18 commits into from
Jan 14, 2025
Merged

Conversation

jimmyjames
Copy link
Contributor

@jimmyjames jimmyjames commented Dec 19, 2024

Introduces support for the server-side batch check API, released in OpenFGA v1.8.2.

Warning

Breaking Change! This change renames the existing batchCheck method (which calls the /check API in parallel) to clientBatchCheck. If you would like to continue to use the client-side batch check, replace your calls to batchCheck with clientBatchCheck, and reference the results using the result property (formerly was responses).

Description

Provides support for the server-side batch check API, introduced in OpenFGA v1.8.2.

Example

Example pulled from the example app updated in this PR.

// execute a batch check
// can pass correlation ID to look up in results, or if not passed one will be generated for you
const userCorrelationId = randomUUID();
const { responses } = await fgaClient.batchCheck({
  checks: [
    {
      // should have access
      user: "user:123",
      relation: "viewer",
      object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
      context: {
        ViewCount: 100
      },
      correlationId: userCorrelationId,
    },
    {
      // should NOT have access
      user: "user:123",
      relation: "viewer",
      object: "document:7772ab2a-d83f-756d-9397-c5ed9f3cb69a",
    }
  ]
});

const anneAllowed = responses.filter(r => r.correlationId === userCorrelationId);
console.log(`Anne is allowed access to ${anneAllowed.length} documents`);
anneAllowed.forEach(item => {
  console.log(`Anne is allowed access to ${item.request.object}`);
});

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@codecov-commenter
Copy link

codecov-commenter commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 95.77465% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.00%. Comparing base (24f8188) to head (55a053f).

Files with missing lines Patch % Lines
api.ts 86.95% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
+ Coverage   87.65%   88.00%   +0.35%     
==========================================
  Files          23       23              
  Lines        1142     1201      +59     
  Branches      198      191       -7     
==========================================
+ Hits         1001     1057      +56     
- Misses         83       85       +2     
- Partials       58       59       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jimmyjames jimmyjames marked this pull request as ready for review January 8, 2025 20:16
@jimmyjames jimmyjames requested review from a team as code owners January 8, 2025 20:16
evansims
evansims previously approved these changes Jan 9, 2025
Copy link
Member

@ewanharris ewanharris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Just a query about the response shape

configuration.ts Show resolved Hide resolved
client.ts Outdated Show resolved Hide resolved
rhamzeh
rhamzeh previously approved these changes Jan 13, 2025
@rhamzeh rhamzeh enabled auto-merge January 14, 2025 18:19
@rhamzeh rhamzeh added this pull request to the merge queue Jan 14, 2025
Merged via the queue into main with commit 18c8f03 Jan 14, 2025
17 checks passed
@rhamzeh rhamzeh deleted the feat/batch-check branch January 14, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants